const request = indexedDB.open('myDataBase', 1);

request.onupgradeneeded = (event) => {
  const db = event.target.result;
  const store = db.createObjectStore('myDataStore', { keyPath: 'id' });
};
request.onsuccess = (event) => {
  const db = event.target.result;
  const transaction = db.transaction(['myDataStore'], 'readwrite');
  const store = transaction.objectStore('myDataStore');
  store.put({ id: 1, data: data });
};

// 读取数据
const transaction = db.transaction(['myDataStore'], 'readonly');
const store = transaction.objectStore('myDataStore');
const getRequest = store.get(1);
getRequest.onsuccess = (event) => {
  const retrievedData = event.target.result.data;
};